Skip to content

feat: add bulk scope support to PUT /api/authz/v1/roles/users/#256

Merged
mariajgrimaldi merged 5 commits intoopenedx:mainfrom
eduNEXT:crls/bulk-scope-role-assignment
Apr 16, 2026
Merged

feat: add bulk scope support to PUT /api/authz/v1/roles/users/#256
mariajgrimaldi merged 5 commits intoopenedx:mainfrom
eduNEXT:crls/bulk-scope-role-assignment

Conversation

@ccantillo
Copy link
Copy Markdown
Contributor

Description

Adds bulk scope support to the existing PUT /api/authz/v1/roles/users/ endpoint.

Previously, the endpoint only accepted a single scope string, requiring one request per scope when assigning a role across multiple scopes. This change introduces a new scopes list field that allows assigning a role to one or more users across multiple scopes in a single request.

Closes #231

Changes

  • AddUsersToRoleWithScopeSerializer: made scope optional and added a scopes list field. The validate() method normalizes both formats into a unified scopes list, validating existence and role availability for every scope.
  • RoleUserAPIView.put(): updated to iterate over data["scopes"], including a scope field in every completed/error response entry.
  • Tests: added cases for multi-scope payloads, single-scope via scopes field, rejection of ambiguous inputs (both/neither field provided), and verification that response entries carry the scope field.

Backward Compatibility

The existing scope (single string) field continues to work exactly as before. Existing clients are unaffected — the only additive change to the response is a scope field on each entry.

Old payload (still supported):

{
  "users": ["contributor"],
  "role": "library_author",
  "scope": "lib:WGU:CSPROB"
}

New payload:

{
  "users": ["contributor"],
  "role": "library_author",
  "scopes": ["lib:WGU:CSPROB", "lib:WGU:OTHER"]
}

Response (both formats):

{
  "completed": [
    {"user_identifier": "contributor", "scope": "lib:WGU:CSPROB", "status": "role_added"},
    {"user_identifier": "contributor", "scope": "lib:WGU:OTHER", "status": "role_added"}
  ],
  "errors": []
}

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 13, 2026
@openedx-webhooks
Copy link
Copy Markdown

Thanks for the pull request, @ccantillo!

This repository is currently maintained by @openedx/committers-openedx-authz.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for this! I left a few comments for you to review.

Mainly, I'd like to understand why this API needs to be backward compatible. I think we are still in the early stages of the framework, so making things backward-compatible might just make it more complex for us to maintain going forward. Just a note to consider.

FYI @rodmgwgu

Comment thread openedx_authz/rest_api/v1/serializers.py
Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
Comment thread openedx_authz/rest_api/v1/serializers.py Outdated
@ccantillo
Copy link
Copy Markdown
Contributor Author

Thanks so much for this! I left a few comments for you to review.

Mainly, I'd like to understand why this API needs to be backward compatible. I think we are still in the early stages of the framework, so making things backward-compatible might just make it more complex for us to maintain going forward. Just a note to consider.

FYI @rodmgwgu

Thanks for the review. The issue #231 states "keep backwards compatibility", so that's a requirement rather than a design choice on my end. That said, it's a fair point to raise. if @rodmgwgu agrees we can break it

Copy link
Copy Markdown
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I don't know enough about the frontend impl to say whether maintaining backwards compatibility would save FE developer time at this point but that may have been a reason why it was in the requirements

@rodmgwgu
Copy link
Copy Markdown
Contributor

Thanks so much for this! I left a few comments for you to review.
Mainly, I'd like to understand why this API needs to be backward compatible. I think we are still in the early stages of the framework, so making things backward-compatible might just make it more complex for us to maintain going forward. Just a note to consider.
FYI @rodmgwgu

Thanks for the review. The issue #231 states "keep backwards compatibility", so that's a requirement rather than a design choice on my end. That said, it's a fair point to raise. if @rodmgwgu agrees we can break it

I specified keeping backwards compatibility to avoid breaking the existing libraries team management view in the admin dashboard, mostly so we don't have a broken state while the new frontend view is fully implemented and merged.

Copy link
Copy Markdown
Contributor

@rodmgwgu rodmgwgu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, please update the CHANGELOG and version.

@ccantillo ccantillo force-pushed the crls/bulk-scope-role-assignment branch 2 times, most recently from 8a41ef9 to fdae762 Compare April 16, 2026 17:36
@ccantillo
Copy link
Copy Markdown
Contributor Author

Looking good, please update the CHANGELOG and version.

Done! Bumped the version and added the entry to the CHANGELOG.

@rodmgwgu
Copy link
Copy Markdown
Contributor

rodmgwgu commented Apr 16, 2026

Looking good, please update the CHANGELOG and version.

Done! Bumped the version and added the entry to the CHANGELOG.

Thanks!, it seems there are some conflicts yet caused by other merges, sorry for that. Can you update that please?

Accept a new  list field alongside the existing  string,
allowing role assignment across multiple scopes in one request while
keeping full backward compatibility. Each response entry now includes
a  field.
@ccantillo ccantillo force-pushed the crls/bulk-scope-role-assignment branch from fdae762 to 2d5ab84 Compare April 16, 2026 17:51
@ccantillo
Copy link
Copy Markdown
Contributor Author

Thanks!, it seems there are some conflicts yet caused by other merges, sorry for that. Can you update that please?

Done! Conflicts resolved and branch updated

for user_identifier in data["users"]:
response_dict = {"user_identifier": user_identifier, "scope": scope_value}
try:
user = get_user_by_username_or_email(user_identifier)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question: what happens if the user is not activated? Should we assign them a role?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question, in this case, this logic already existed and we don't have a specific requirement for this, perhaps we should create a tech debt issue to review this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks

Copy link
Copy Markdown
Contributor

@rodmgwgu rodmgwgu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for attending this, LGTM!

Copy link
Copy Markdown
Contributor

@dwong2708 dwong2708 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

Comment thread CHANGELOG.rst Outdated
@ccantillo ccantillo force-pushed the crls/bulk-scope-role-assignment branch from 2b39ec6 to f47d361 Compare April 16, 2026 18:27
Copy link
Copy Markdown
Member

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all my comments!

@mariajgrimaldi mariajgrimaldi merged commit d852f05 into openedx:main Apr 16, 2026
8 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Triage to Done in Contributions Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Task - RBAC AuthZ - Modify role assignment endpoint for Admin Console

7 participants